<template>
  <div class="lb-dis-commission">
    <top-nav></top-nav>
    <div class="page-main">
      <el-row class="page-search-form">
        <el-form
          @submit.native.prevent
          :inline="true"
          :model="searchForm"
          ref="searchForm"
        >
          <el-form-item label="输入查询" prop="name">
            <el-input
              v-model="searchForm.name"
              placeholder="请输入姓名/微信昵称"
            ></el-input>
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select v-model="searchForm.status" placeholder="请选择">
              <el-option
                v-for="item in statusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <lb-button
              size="medium"
              type="primary"
              icon="el-icon-search"
              style="margin-right: 5px"
              @click="getTableDataList(1)"
              >{{ $t('action.search') }}</lb-button
            >
            <lb-button
              size="medium"
              icon="el-icon-refresh-left"
              style="margin-right: 5px"
              @click="resetForm('searchForm')"
              >{{ $t('action.reset') }}</lb-button
            >
          </el-form-item>
        </el-form>
      </el-row>
      <el-table
        v-loading="loading"
        :data="tableData"
        :header-cell-style="{ background: '#f5f7fa', color: '#606266' }"
        style="width: 100%"
      >
        <el-table-column prop="id" label="ID" width="60"></el-table-column>
        <el-table-column prop="name" label="姓名"></el-table-column>
        <el-table-column prop="name" label="微信昵称"></el-table-column>
        <el-table-column prop="source_name" label="佣金来源"></el-table-column>
        <el-table-column
          prop="out_trade_no"
          label="系统订单号"
          min-width="160"
        ></el-table-column>
        <el-table-column
          prop="transaction_id"
          label="商户订单号"
          min-width="160"
        ></el-table-column>
        <el-table-column prop="type" label="类型"></el-table-column>
        <el-table-column prop="waiting" label="状态"></el-table-column>
        <el-table-column prop="price" label="订单金额"></el-table-column>
        <el-table-column prop="extract" label="提成比例/金额" min-width="120">
          <template slot-scope="scope">
            <span>{{
              scope.row.selling_type === 1
                ? scope.row.extract_cash
                : scope.row.extract + '%'
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="moeny"
          label="此单提成金额"
          min-width="120"
        ></el-table-column>
        <el-table-column label="时间">
          <template slot-scope="scope">
            <p>{{ scope.row.create_time | handleTime(1) }}</p>
            <p>{{ scope.row.create_time | handleTime(2) }}</p>
          </template>
        </el-table-column>
      </el-table>
      <lb-page
        :batch="false"
        :page="searchForm.page"
        :pageSize="searchForm.limit"
        :total="total"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChange"
      ></lb-page>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      statusOptions: [
        {
          label: '全部',
          value: 0
        },
        {
          label: '未入账',
          value: 1
        },
        {
          label: '已入账',
          value: 2
        },
        {
          label: '已退款',
          value: 3
        }
      ],
      searchForm: {
        limit: 10,
        page: 1,
        name: '',
        status: ''
      },
      loading: false,
      total: 0,
      tableData: []
    }
  },
  activated () {
    this.getTableDataList()
  },
  methods: {
    resetForm (name) {
      this.$refs[name].resetFields()
      this.getTableDataList(1)
    },
    getTableDataList (flag) {
      if (flag) this.searchForm.page = 1
      this.loading = true
      let { searchForm } = this
      console.log(searchForm)
      this.$api.getDistributionCommissionList(searchForm).then(res => {
        console.log(res)
        this.loading = false
        if (res.code === 200) {
          this.total = res.data.total
          this.tableData = res.data.data
        }
      })
    },
    delReocde (id) {
      console.log(id)
    },
    handleSizeChange (val) {
      this.searchForm.limit = val
      this.handleCurrentChange(1)
    },
    handleCurrentChange (val) {
      this.searchForm.page = val
      this.getTableDataList()
    }
  },
  filters: {
    handleTime (val, type) {
      let time = type === 1 ? moment(val * 1000).format('YYYY-MM-DD') : type === 2 ? moment(val * 1000).format('HH:mm:ss') : moment(val * 1000).format('YYYY-MM-DD HH:mm:ss')
      return time
    }
  }
}
</script>

<style lang="scss" scoped>
.lb-dis-commission {
  width: 100%;
  .el-input,
  .el-select {
    width: 200px;
  }
}
</style>
